<?php

namespace App\Admin\Controllers;

use App\Models\Reports;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class ReportController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '报错列表';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Reports);
        $grid->model()->orderBy('id', 'desc');

        $grid->column('id', __('Id'));
        $grid->column('user_id', __('用户 id'));
        $grid->column('user.mobile', __('用户手机号'));
        $grid->column('book_id', __('书籍 id'));
        $grid->column('book.name', __('书籍名称'));
        $grid->column('book_chapter_id', __('章节 id'));
        $grid->column('chapter.name', __('章节名称'));
        $grid->column('en_word', __('问题单词'));
        $grid->column('opt_desc', __('具体选项'));
        $grid->column('other_desc', __('其他描述'));
        $grid->column('status', __('处理状态'));
        $grid->column('mark', __('处理备注'));
        $grid->column('created_at', __('提交时间'));
        $grid->column('updated_at', __('更新时间'));

        $grid->disableCreateButton();
        $grid->disableColumnSelector();

        $grid->actions(function (Grid\Displayers\Actions $actions){
            $actions->disableView();
            $actions->disableDelete();
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Reports::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('user_id', __('User id'));
        $show->field('book_id', __('Book id'));
        $show->field('book_chapter_id', __('Book chapter id'));
        $show->field('en_word', __('En word'));
        $show->field('opt_desc', __('Opt desc'));
        $show->field('other_desc', __('Other desc'));
        $show->field('status', __('Status'));
        $show->field('mark', __('Mark'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Reports);

        $form->display('user_id', __('用户 id'));
        $form->display('book_id', __('数据 id'));
        $form->display('book_chapter_id', __('章节 id'));
        $form->text('en_word', __('问题单词'));
        $form->text('opt_desc', __('具体选项'));
        $form->textarea('other_desc', __('其他描述'));
        $form->radio('status', __('处理状态'))->options(Reports::$statusLabels)->default(0);
        $form->textarea('mark', __('处理备注'));

        return $form;
    }
}
